# Maintainer: Andrea Zagli <andrea.zagli.free@gmail.com>

_realname=evince
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.36.6
pkgrel=1
arch=('any')
pkgdesc="Document (PostScript, PDF) viewer (mingw-w64)"
license=("GPL 2")
url="https://www.gnome.org"
options=('strip' 'staticlibs')
depends=("${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-cairo"
         "${MINGW_PACKAGE_PREFIX}-djvulibre"
         "${MINGW_PACKAGE_PREFIX}-gsettings-desktop-schemas"
         "${MINGW_PACKAGE_PREFIX}-appstream-glib"
         "${MINGW_PACKAGE_PREFIX}-gspell"
         "${MINGW_PACKAGE_PREFIX}-gst-plugins-base"
         "${MINGW_PACKAGE_PREFIX}-gtk3"
         "${MINGW_PACKAGE_PREFIX}-hicolor-icon-theme"
         "${MINGW_PACKAGE_PREFIX}-libarchive"
         "${MINGW_PACKAGE_PREFIX}-libgxps"
         "${MINGW_PACKAGE_PREFIX}-libspectre"
         "${MINGW_PACKAGE_PREFIX}-libtiff"
         "${MINGW_PACKAGE_PREFIX}-nss"
         "${MINGW_PACKAGE_PREFIX}-poppler"
         "${MINGW_PACKAGE_PREFIX}-zlib")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-gettext"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-gtk-doc"
             "${MINGW_PACKAGE_PREFIX}-itstool"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-yelp-tools")
source=(https://download.gnome.org/sources/${_realname}/${pkgver%.*}/${_realname}-${pkgver}.tar.xz
        0002-missing-include.patch
        0003-mingw-dont-have-fcntl.patch
        0005-previewer-unix-prin-only.patch
        0007-meson-fixes.patch)
sha256sums=('95ce9b21c6fc7c837e12eb6e88777ea80dcc2ce6d84d000166a24a113a6d8db0'
            'd2850c4bdfa87fa56bae2674d2c798f9181bfb3f19319fbc9966672caae48237'
            '035f9cd952daa040d32309398b73022d199e27fed756126eb15663fb6a435c45'
            '4e6a1ae77d36f0b36ea68ec2cc3abe4a706355ba02e4066d1b9add138052ba1b'
            'b15ad558c060a62c03e54cb08696f859485708d29e317bd6e7d163cac0cfd368')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}

  patch -p1 -i ${srcdir}/0002-missing-include.patch
  patch -p1 -i ${srcdir}/0003-mingw-dont-have-fcntl.patch
  patch -p1 -i ${srcdir}/0005-previewer-unix-prin-only.patch
  patch -p1 -i ${srcdir}/0007-meson-fixes.patch
}

build() {
  [[ -d build-${MINGW_CHOST} ]] && rm -rf build-${MINGW_CHOST}
  mkdir -p build-${MINGW_CHOST} && cd build-${MINGW_CHOST}

   ${MINGW_PREFIX}/bin/meson \
     --buildtype=plain \
     -Dplatform=win32 \
     -Dbrowser_plugin=false \
     -Ddbus=false \
     -Dnautilus=false \
     -Dgtk_doc=false \
     -Dgtk_unix_print=disabled \
     "../${_realname}-${pkgver}"

  ${MINGW_PREFIX}/bin/ninja
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"

  DESTDIR="${pkgdir}${MINGW_PREFIX}" ninja install

 for pcfile in  "${pkgdir}${MINGW_PREFIX}"/lib/pkgconfig/*.pc; do
    sed -s "s|$(cygpath -m ${MINGW_PREFIX})|${MINGW_PREFIX}|g" -i "${pcfile}"
  done

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
